#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> mymap;
        for (const string& str : strs) {
            string key = str;
            sort(key.begin(), key.end(), less<char>()); // 排序字符串中的字符
            mymap[key].emplace_back(str);
        }
        vector<vector<string>> ret;
        for (auto it = mymap.begin(); it != mymap.end(); ++it) {
            ret.emplace_back(it->second);
        }
        return ret; //注意strs为空的情况！
    }
};